package com.cskaoyan.market.util;

import com.cskaoyan.market.exception.ParameterException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
/**
 * @Author: 鲸落
 * @Date: 2024/05/20/15:07
 * @Version: 1.0
 * @Description:
 */
public class ValidationUtils {
    public static void validate(BindingResult bindingResult) {
        if(bindingResult.hasErrors()){
            //有出错
            FieldError fieldError = bindingResult.getFieldError();
            String field = fieldError.getField();
            String defaultMessage = fieldError.getDefaultMessage();
            throw new ParameterException(defaultMessage);
        }
    }
}
